<template>
  <div class="box">
    <RenderTable 
      :superQueryFieldList="superQueryFieldList" 
      :queryParamArr = "queryParamArr"
      :defColumns="defColumns"
      :url = "url"
      :rowSelectionType = "'radio'"
      :isShowRowSelection = 'true'
      @onSelectChange = 'onSelectChange'
      @handleEdit = "handleEdit"
      @handleSubmit = "handleSubmit"
      ref='renderTable'
    >
    
      <template slot="btn">
        <p-button type="primary" @click="showAddModal" style="margin-right: 10px">新增</p-button>
      </template>

      <template v-slot:action = '{record}'>
        <a @click="handleEdit(record)">编辑</a>      
        <p-divider type="vertical" />
        <a @click="handleSubmit(record)">提交审批</a>    
        <p-divider type="vertical" />
        <p-popconfirm
          title="确定删除吗?"
          @confirm="() => handleDelete(record.id)"
        >
          <a>删除</a>     
        </p-popconfirm>
      </template>

    </RenderTable>

    <MemberSkillAdjustModal ref='memberSkillAdjustModal' @handleSuccess = 'handleSuccess'></MemberSkillAdjustModal>
    
    <MemberSkillAdjustDetail v-show="selectedId !='' " :selectedId="selectedId" :lineno="lineno"></MemberSkillAdjustDetail>

  </div>
</template>

<script type="text/javascript">
import RenderTable from '@/components/renderTable'
import MemberSkillAdjustModal from './modules/memberSkillAdjustModal.vue'
import MemberSkillAdjustDetail from './modules/memberSkillAdjustDetail.vue'
import { postAction, getAction, deleteAction, putAction } from "@/api/manage";

const superQueryFieldList =
[
  {
    value: "organization",
    text: "组织",
    type: "String",
  }, 
  {
    value: "empname",
    text: "员工姓名",
    type: "String",
  },
]
export default {
  data() {
    return {
      superQueryFieldList,
      queryParamArr: [
        {
          label: "技能名称",
          placeholder: "请输入技能名称",
          type: 'input',
          key: 'skillName',
          value: ''
        }
      ],
      defColumns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: (t, r, index) => {
            return parseInt(index) + 1;
          },
        },
        {
          title: "单据号",
          align: "center",
          dataIndex: "orderno",
        },
        {
          title: "日期",
          align: "center",
          dataIndex: "date",
        },
        {
          title: "车间",
          align: "center",
          dataIndex: "workroomname",
        },
        {
          title: "班组",
          align: "center",
          dataIndex: "classname",        
        },
        {
          title: "单据状态",
          align: "center",
          dataIndex: "orderStatus",  
          customRender: (t, r, index) => {
            return {0: '待提交', 1: '审批中', 2: '被驳回', 3: "终止", 4: "发行"}[t];
          },                
        },
        {
          title: "生效日期",
          align: "center",
          dataIndex: "effectiveDate",
        },
        {
          title: "制单人",
          align: "center",
          dataIndex: "maker",
        },
        {
          title: "制单日期",
          align: "center",
          dataIndex: "makeDate",
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      skillPropertyKeys: {},
      selectedId: '',
      lineno: '',
      url: {
        list: '/mes-manpower/mesHrMemberSkillAdjust/list',
        delete: '/mes-manpower/mesHrMemberSkillAdjust',
        submit: '/mes-manpower/mesHrMemberSkillAdjust/submit', // 提交审批
      },
    
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },         
    }
  },



  mounted() {
  },
  methods: {

    handleEdit(record){
      this.$refs.memberSkillAdjustModal.showModal(record)
    },
    // 显示新增弹窗
    showAddModal(){
      this.$refs.memberSkillAdjustModal.showModal()
    },
    handleSuccess(){
      this.$refs.renderTable.loadData()
    },

    onSelectChange(selectionRows){
      console.log(selectionRows);
      console.log(333);
      
      this.selectedId = selectionRows[0].id
      this.lineno =  selectionRows[0].lineno
    },   

    // 提交审批
    handleSubmit(record){
      const params = {
        id: record.id
      }
      getAction(this.url.submit, params).then(res => {
        if(res.success) {
          this.$message.success('提交审批成功')
        }else {
          this.$message.error(res.msg)
        }
      })
    }

  },
  components: {
    RenderTable,
    MemberSkillAdjustModal,
    MemberSkillAdjustDetail
  }
}
</script>

<style lang="less" scoped>
</style>

